import 'package:XinXiZiXun/common/utils/screen.dart';
import 'package:XinXiZiXun/common/values/colors.dart';
import 'package:XinXiZiXun/pages/homepage/homepage.dart';
import 'package:XinXiZiXun/pages/discover/discover.dart';
import 'package:XinXiZiXun/pages/mine/mine.dart';

import 'package:flutter/material.dart';


///tabbarController
class ZdyTabBarPage extends StatefulWidget {
  @override
  _ZdyTabBarPageState createState() => _ZdyTabBarPageState();
}

class _ZdyTabBarPageState extends State<ZdyTabBarPage> {

  ///选择某一个模块
  var _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        selectedFontSize: duSetScaleFontSize(20.0),
        unselectedFontSize: duSetScaleFontSize(20.0),
        selectedItemColor: AppColors.primaryElementColor,
        unselectedItemColor: AppColors.primaryBlackColor,
        type: BottomNavigationBarType.fixed,
        items: [
          addElement('assets/images/icon_tab_home_selected.png', 'assets/images/ic_tab_home_selected.png', '首页'),
          addElement('assets/images/icon_tab_faxian_normal.png', 'assets/images/icon_tab_fond_normal.png', '发现'),
          addElement('assets/images/ic_tab_user_normal.png', 'assets/images/ic_tab_user_selected.png', '我的'),
        ],
        onTap: (index){
            print('点击-----:{$index}');
            setState(() {
              _currentIndex = index;
            });
        },
      ),
      body: IndexedStack(
        index: _currentIndex,
        children: [
          HomePage(),
          DiscoverPage(),
          MinePage(),
        ],
      ),
    );
  }
  
  BottomNavigationBarItem addElement(String iconNormalName, String iconActiveName, String titleName){
    return BottomNavigationBarItem(
        icon: Image.asset(iconNormalName),
        activeIcon: Image.asset(iconActiveName),
        label: titleName
    );
  }
  
}
